package cn.wsn2018.tools.util;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.OutputStream;
import java.net.InetSocketAddress;
import java.net.Socket;

/**
 * 连接通信测试模块的socket通信类
 * 
 */
public class HttpUtil {
	
	public static String postRequest(String url,String requestCode) {
		try{
			//Socket s=new Socket(url,3590);
			Socket s = new Socket();
			s.connect(new InetSocketAddress(url,23590),8000);
			OutputStream os=s.getOutputStream();
			DataOutputStream dos=new DataOutputStream(os);
			dos.write(requestCode.getBytes());
			DataInputStream dis=new DataInputStream(s.getInputStream());
			byte[] buff = new byte[1024];
			int len=dis.read(buff);
			String str=new String(buff,"utf-8");
			dos.flush();
			dos.close();
			dis.close();
			s.close();
			return str;
		}
		catch(Exception e){
			e.printStackTrace();
			return "inner error";
		}
	}
}
